package com.wc.alorithm_blue_bridge._二分.寻找黄金宝藏;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/15 22:22
 * @description
 * https://www.lanqiao.cn/courses/46292/learning/?id=3442367&compatibility=false
 */
public class Main {
    /**
     * 思路：
     * 枚举答案 x
     * 使得 >= x 的个数 cnt - 1 >= (R - L) / 2,  R - L = len >= k
     * 因为, cnt中包含自己所以需要 cnt - 1 >= (R - L) / 2
     * 变形 2 * s[R] - 2 * s[L] - 2 >= R - L
     * 2 * s[R] - R - 2 >= 2 * s[L] - L
     * 我们可以固定 R, 那就相当于寻找最小的 2 * s[L] - L,
     * R - L >= k  =>>  L <= R - k
     * 由此可以得数需要求出 2 * s[L] - L的最小值  0 <= L <= R - k, 可以边枚举 R, 边计算前面最小的 2 * s[L] - L
     *
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] a = new int[N], s = new int[N];
    static int n, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        k = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        int l = 1, r = n;
        while (l < r) {
            int mid = l + r + 1 >> 1;
            if (check(mid)) l = mid;
            else r = mid - 1;
        }
        out.println(r);
        out.flush();
    }

    static boolean check(int x) {
        int minv = (int)1e9, L = -1;
        for (int i = 1; i <= n; i++) {
            if (a[i] >= x) s[i] = s[i - 1] + 1;
            else s[i] = s[i - 1];
            if (i - k >= 0 && minv > 2 * s[i - k] - (i - k)) {
                minv = 2 * s[i - k] - (i - k);
                L = i - k;
            }
            if (L >= 0 && s[i] - s[L] - 1 >= (i - L) / 2) return true;
        }
        return false;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

